package com.yanqu.road.server.cmd.activity.witchdraw;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WitchDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.witchDraw.WitchDrawModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WITCH_DRAW_DRAW, desc = "魔女之夜抽奖")
public class WitchDrawDrawCmd extends AbstractCommand {


    private int activityId;

    private int drawTimes;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WitchDrawProto.WitchDrawDrawReq witchDrawDrawReq = WitchDrawProto.WitchDrawDrawReq.parseFrom(packet.getBytes());
        activityId = witchDrawDrawReq.getActivityId();
        drawTimes = witchDrawDrawReq.getDrawTimes();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(WitchDrawModule.class).draw(activityId, drawTimes);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            WitchDrawProto.WithDrawDrawResp.Builder respMsg = WitchDrawProto.WithDrawDrawResp.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_WITCH_DRAW_DRAW, respMsg);
        }
    }
}
